﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace odinshrine
{
    class MenuSon:Menu
   {
        static GestionPhysics phys = new GestionPhysics();
        public static int bouton1X = 700, bouton1Y = 200, bouton2X = 700, bouton2Y = 300;
        static int position = 0;
        public static bool musiqueCoche = true;
        public static bool bruitagesCoche = true;
        static Texture2D boutonCocher;
        static Texture2D boutonRetour;
        static Texture2D fond_son;
        public static Rectangle bouton1Rect, bouton2Rect;
        public static Rectangle Sonretour;
        public static int SonretourX = 300, sonRetourY = 500;
        static SpriteFont ecriture;
        static TimeSpan timer = TimeSpan.Zero;

        public static void LoadMenuSon(ContentManager Content)
        {
            boutonCocher = Content.Load<Texture2D>("Menu/boutoncocher");
            boutonRetour = Content.Load<Texture2D>("Menu/retour");
            ecriture = Content.Load<SpriteFont>("Fonts/menufont");
            fond_son = Content.Load<Texture2D>("Menu/menu");
            Sonretour = new Rectangle(-1000, sonRetourY, boutonRetour.Width, boutonRetour.Height);
            bouton1Rect = new Rectangle(-1000, bouton1Y, boutonCocher.Width, boutonCocher.Height);
            bouton2Rect = new Rectangle(-1000, bouton2Y, boutonCocher.Width, boutonCocher.Height);
        }

        public static void Gestion(MouseState mouse, KeyboardState clavier, GameTime gameTime)
        {
            if (timer.Milliseconds > 150)
            {
                if (mouse.LeftButton == ButtonState.Pressed)
                {
                    if (phys.collisionRectangleRectangle(bouton1Rect, new Rectangle(mouse.X, mouse.Y, 1, 1)))
                    {
                        musiqueCoche = !musiqueCoche;
                    }
                    if (phys.collisionRectangleRectangle(bouton2Rect, new Rectangle(mouse.X, mouse.Y, 1, 1)))
                    {
                        bruitagesCoche = !bruitagesCoche;
                    }
                    timer = TimeSpan.Zero;
                }
            }

            if (clavier.IsKeyDown(Keys.Down) && position != 1)
            {
                position++;
            }

            if (position == 1 && clavier.IsKeyDown(Keys.Enter))
            {
                menu_son = false;
                bouton1Rect.X = -1000;
                bouton2Rect.X = -1000;
                Sonretour.X = -1000;
                Options.sonRect.X = Options.sonX;
                Options.menuRect.X = Options.menuX;
                Options.commandesRect.X = Options.commandesX;
                position = 0;
            }
            timer += gameTime.ElapsedGameTime;
        }

        public static void DrawSon(SpriteBatch spriteBatch, MouseState mouse)
        {
            spriteBatch.Draw(fond_son, new Vector2(0, 0), Color.White);
            spriteBatch.Draw(boutonRetour, new Vector2(SonretourX, sonRetourY), Color.White);
            spriteBatch.DrawString(ecriture, "Musique de fond", new Vector2(420, 200), Color.White);
            spriteBatch.DrawString(ecriture, "Bruitages", new Vector2(450, 300), Color.White);
            if (musiqueCoche)
            {
                spriteBatch.Draw(boutonCocher, new Vector2(bouton1X, bouton1Y), Color.Blue);
            }
            else
            {
                spriteBatch.Draw(boutonCocher, new Vector2(bouton1X, bouton1Y), Color.White);
            }
            if (bruitagesCoche)
            {
                spriteBatch.Draw(boutonCocher, new Vector2(bouton2X, bouton2Y), Color.Blue);
            }
            else
            {
                spriteBatch.Draw(boutonCocher, new Vector2(bouton2X, bouton2Y), Color.White);
            }
            if (position == 1)
            {
                spriteBatch.Draw(Mainmenu.imgBouton, new Vector2(SonretourX - 70, sonRetourY), Color.White);
            }
        }
    }
}
